#include <REGX52.H>
int count1=0;
/**
 * 菜单控制LED
 * 1. 正向流水灯
 * 2. 反向流水灯
 * 3. 正向计时功能
 * 4. 倒计时功能
 *
 * 功能模式按键，菜单前进按键，菜单后退按键
 */
int i;
void delay_ms(unsigned int ms)
{
    unsigned int i, j;
    for (i = 0; i < ms; i++)
    {
        for (j = 0; j < 123; j++)
            ;
    }
}

void waterlighting()
{
   while(1)
   {
   for(i=0;i<8;i++)
   {
    P2=~(0x01 << i);
    delay_ms(500);
   }
   }
}
void sidewaterlignting()
{
   while(1)
   {for(i=0;i<=8;i++)
   {
    P2=~(0x80 >> i);
    delay_ms(500);
   }
}
}

void countertime()
{
    P2=0xFF;
    while(1)
    {
    P2=P2-1;
    delay_ms(1000);
    }
}
void anticount()
{
    P2=0x00;
    while(1)
    {
     P2=P2+1;
     delay_ms(1000);
    }
}

void main()
{
   while(1)
   {
     if(P3_1==0)
     {
       while(P3_1==0){}
       count1++;
     }
     if(P3_2==0)
     {
       while(P3_2==0){}
       count1--;
     }
     if(P3_0==0)
     {
       while(P3_0==0){}
       switch(count1)
       {
        case 0:
          waterlighting();
          break;
        case 1:
          sidewaterlignting();
          break;
        case 2:
          countertime();
          break;
        case 3:
          anticount();
          break;
        default:
          break;
       }
        if(count1>=4||count1<0)
        {
           count1=0;
        }
     }
   }
}
